package com.aiwu.memory;

import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.aiwu.library.App;
import com.aiwu.library.util.DisplayUtil;

import org.citra.citra_emu.R;

/**
 * 准确搜索
 * 回游戏改数值后的界面
 */
public class MemoryNormalBackGameFragment extends BaseLazyFragment implements MemoryManager.KeyBoardOffsetCallback {
    private TextView tvTip;
    private EditText etNum;

    @Override
    protected void lazyLoad() {
        String endStr = " 变成了";
        String tipStr = MemoryManager.getInstance().getLastSearchValue() + endStr;
        SpannableString ssTip = new SpannableString(tipStr);
        int start = 0;
        int end = tipStr.indexOf(endStr);
        ssTip.setSpan(new ForegroundColorSpan(ContextCompat.getColor(App.getContext(), R.color.text_imp)), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        ssTip.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        tvTip.setText(ssTip);
        etNum.requestFocus();
    }

    @Override
    protected Boolean repeatedLoad() {
        return true;
    }

    @Override
    protected int initContentView() {
        return R.layout.fragment_memory_back_game_normal;
    }

    @Override
    protected void initView(View view) {
        tvTip = view.findViewById(R.id.tv_tip);
        etNum = view.findViewById(R.id.et_num);
        MemoryManager.disableShowInput(etNum, true, this);
    }

    @Override
    public boolean setKeyBoardOffset(ViewGroup.MarginLayoutParams layoutParams) {
        if (DisplayUtil.isPortrait()) {
            layoutParams.setMargins(0, getView().getHeight() - getResources().getDimensionPixelOffset(R.dimen.qb_px_30), 0, 0);
            return true;
        }
        return false;
    }
}
